/*
 * @lc app=leetcode.cn id=107 lang=javascript
 *
 * [107] 二叉树的层次遍历 II
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[][]}
 */
var levelOrderBottom = function(root) {
    if(!root){return []}
    let queue=[root]
    let ans=[]
    while(queue.length){
        let sbuAns=[]
        let size=queue.length
        for(let i=0;i<size;i++){
            let cur=queue.shift()
            sbuAns.push(cur.val)
            if(cur.left){queue.push(cur.left)}
            if(cur.right){queue.push(cur.right)}
        }
        ans.unshift(sbuAns)
    }
    return ans
};
// @lc code=end

